// 6.59 编写算法完成下列操作：无重复地输出以孩子-兄弟链表存储的树T中所有的边。输出的形式为(k1, k2), …, (ki, kj), …,其中，ki和kj为树结点中的结点标识。
#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"

void fun_6_59(tree *root)
{
	tree *queue[100];
	int front, rear;
	front = rear = 0;
	queue[rear++] = root;
	int count = 0;
	int maxdegree = 0;
	int m, n;
	m = 1, n = 0;
	while (front < rear)
	{
		tree *p = queue[front++];
		m--;
		tree *t = p->left;
		if (!t)
			count++;
		while (t)
		{
			printf("<%3d,%3d>", p->data, t->data);
			queue[rear++] = t;
			n++;
			t = t->right;
		}
		if (m == 0)
		{
			if (n > maxdegree)
				maxdegree = n;
			m = n;
			n = 0;
		}
	}
	printf("\n%3d\n%3d", count, maxdegree);
}

int main()
{
	/*******************code*******************/
	int n = 31;
	int a[31] = {1,
				 2, NULL,
				 8, 3, NULL, NULL,
				 NULL, NULL, 4, 5, NULL, NULL, NULL, NULL,
				 NULL, NULL, NULL, NULL, NULL, NULL, NULL, 6, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
	tree *root;
	CreatTree(root, a, n, 0);
	fun_6_59(root);
	/******************************************/
	printf("\n\n****************************\n");
	printf("Press Enter key to continue\n");
	getchar();
	return 0;
	/******************************************/
}
